/* hal_lptmr.h */
#ifndef __HAL_LPTMR_H__
#define __HAL_LPTMR_H__

#include "hal_common.h"

typedef enum
{
    LPTMR_ClkDiv_2 = 0u,
    LPTMR_ClkDiv_4 = 1u,
    LPTMR_ClkDiv_8 = 2u,
    LPTMR_ClkDiv_16 = 3u,
    LPTMR_ClkDiv_32 = 4u,
    LPTMR_ClkDiv_64 = 5u,
    LPTMR_ClkDiv_128 = 6u,
    LPTMR_ClkDiv_256 = 7u,
    LPTMR_ClkDiv_512 = 8u,
    LPTMR_ClkDiv_1024 = 9u,
    LPTMR_ClkDiv_2048 = 10u,
    LPTMR_ClkDiv_4096 = 11u,
    LPTMR_ClkDiv_8192 = 12u,
    LPTMR_ClkDiv_16384 = 13u,
    LPTMR_ClkDiv_32768 = 14u,
    LPTMR_ClkDiv_65536 = 15u,

    LPTMR_ClkDiv_Bypass = 16u,
} LPTMR_ClkDiv_Type;

typedef enum
{
    LPTMR_ClkSrc_Alt0 = 0u, /* from ipc func clock. */
    LPTMR_ClkSrc_Alt1 = 1u, /* from sirc. */
    LPTMR_ClkSrc_Alt2 = 2u, /* from sxosc. */
} LPTMR_ClkSrc_Type;

typedef struct
{
    LPTMR_ClkDiv_Type ClkDiv; /* prescaler. */
    uint32_t ModVal;    
} LPTMR_TimeCounterInit_Type;

void LPTMR_InitTimeCounter(lpTMR_Type * base, LPTMR_TimeCounterInit_Type * init);

typedef enum
{
    LPTMR_PulseInputSrc_Alt0 = 0u, /* from PMU. */
    LPTMR_PulseInputSrc_Alt1 = 1u, /* from lptmr_alt1 pin. */
    LPTMR_PulseInputSrc_Alt2 = 2u, /* from lptmr_alt2 pin. */
    LPTMR_PulseInputSrc_Alt3 = 3u, /* from lptmr_alt3_pin. */
} LPTMR_PulseInputSrc_Type;

typedef enum
{
    LPTMR_PulseInputPol_RisingEdge = 0u,
    LPTMR_PulseInputPol_FallingEdge = 1u,
} LPTMR_PulseInputPol_Type;

typedef enum
{
    LPTMR_PulseInputGlitch_2 = 1u,
    LPTMR_PulseInputGlitch_4 = 2u,
    LPTMR_PulseInputGlitch_8 = 3u,
    LPTMR_PulseInputGlitch_16 = 4u,
    LPTMR_PulseInputGlitch_32 = 5u,
    LPTMR_PulseInputGlitch_64 = 6u,
    LPTMR_PulseInputGlitch_128 = 7u,
    LPTMR_PulseInputGlitch_256 = 8u,
    LPTMR_PulseInputGlitch_512 = 9u,
    LPTMR_PulseInputGlitch_1024 = 10u,
    LPTMR_PulseInputGlitch_2048 = 11u,
    LPTMR_PulseInputGlitch_4096 = 12u,
    LPTMR_PulseInputGlitch_8192 = 13u,
    LPTMR_PulseInputGlitch_16384 = 14u,
    LPTMR_PulseInputGlitch_32768 = 15u,

    LPTMR_PulseInputGlitch_Bypass = 16u,
} LPTMR_PulseInputGlitch_Type;


typedef struct
{
    LPTMR_PulseInputSrc_Type PulseInputSrc;
    LPTMR_PulseInputPol_Type PulseInputPol;
    LPTMR_PulseInputGlitch_Type PulseInputGlitch; /* prescaler. */
    uint32_t ModVal;    
} LPTMR_PulseCounterInit_Type;

void LPTMR_InitPulseCounter(lpTMR_Type * base, LPTMR_PulseCounterInit_Type * init);

/* flags for interrupt & status. */
#define LPTMR_FLAG_MATCH_MOD    lpTMR_STS_CCF_MASK

void LPTMR_EnableInterrupts(lpTMR_Type * base, uint32_t flags);
void LPTMR_DisableInterrupts(lpTMR_Type * base, uint32_t flags);
void LPTMR_EnableDma(lpTMR_Type * base, bool enable);
uint32_t LPTMR_GetStatusFlags(lpTMR_Type * base);
void LPTMR_ClearStatusFlags(lpTMR_Type * base, uint32_t flags);
void LPTMR_StartCounter(lpTMR_Type * base);
void LPTMR_StopCounter(lpTMR_Type * base);

#endif /* __HAL_LPTMR_H__ */

